﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Shell;
using System.Windows.Threading;
using Ay.MvcFramework.Wpf;
using Ay.Framework.WPF.Controls;
using Ay.MvcFramework;
using Hotel.UI.Common;
using Hotel.UI.Controllers;
using Hotel.UI.Controls;
using Hotel.UI.Models;
using Hotel.Reports;
using Ay.Framework.WPF;

namespace Hotel.UI.Views
{
    public class MyList : ObservableCollection<IAyCheckedItem>
    {

    }

    /// <summary>
    /// _ViewStartView.xaml 
    /// 创建时间：2017/9/5 11:57:44
    /// </summary>
    public partial class Main : AyWindow
    {
        private List<string> list_0;

        private List<string> list_1;

        private List<double> list_2;
        private BrushConverter brushConverter_0;

        private DispatcherTimer dispatcherTimer_0;

        private ObservableCollection<AyArcModel> observableCollection_0;
        //ObservableCollection<RoomStatusModel> roomList2 = new ObservableCollection<RoomStatusModel>();
        //public MainController Controller => base.DataContext as MainController;
        public Main()
        {
            InitializeComponent();
            ayuiTaskBar.Visibility = Visibility.Visible;
            this.SkinWindowMethodOverride = () =>
            {
                AyWindowManager<SkinSetWindow>.Show((t) =>
                {
                    t.Owner = this;
                    t.ShowInTaskbar = false;
                    //t.AfterSetSkinMethodOverride = () =>
                    //{
                    //    try
                    //    {
                    //        for (var i = ayuiTaskBar.ContextMenu.Items.Count - 1; i >= 0; i--)
                    //        {
                    //            MenuItem item = ayuiTaskBar.ContextMenu.Items[i] as MenuItem;
                    //            if (item == null) continue;
                    //            var key = item.GetDynamicResourceKey(HeaderedItemsControl.HeaderProperty) as string;
                    //            if (!string.IsNullOrEmpty(key))
                    //                item.SetResourceReference(HeaderedItemsControl.HeaderProperty, key);
                    //        }
                    //    }
                    //    catch (System.Exception ex)
                    //    {
                    //        //MyAyMessageBox.Show(ex.Message);

                    //    }
                    //};

                }, null);
            };

            MainController Controller = new MainController();
            Controller.Model.ShowWindowCommand = new DelegateCommand(ShowWindow, () => !System.Windows.Application.Current.MainWindow.IsVisible);
            Controller.Model.HideWindowCommand = new DelegateCommand(HideWindow, () => System.Windows.Application.Current.MainWindow.IsVisible);
            Controller.Model.LeftClickShowWindowCommand = new DelegateCommand(ShowActiveWindow, () => true);
            ayuiTaskBar.DataContext = Controller.Model;

            Controller.ChangeHeaderIconCommand = new DelegateCommand((p) =>
            {

                var ssss = 0000;


            },
            () =>
            true
            );
            this.DataContext = Controller;

            for (int i = 0; i < 100; i++)
            {
                Controller.Model.roomList2.Add(new RoomStatusModel()
                {
                    Building = "1",
                    Floor = (new Random(i).Next(1, 8)).ToString().PadLeft(2, '0'),
                    GuestCount = (new Random(i + DateTime.Now.Millisecond + (new Random(i).Next(1, 8000))).Next(1, 7))
                    ,
                    No = "1001",
                    Type = "温馨大床"
                });
            }
            Controller.Model.roomList2 = Controller.Model.roomList2.OrderBy(x => x.Building).OrderBy(x => x.Floor).OrderBy(x => x.No).ToObservableCollection();
            //this.DataContext = roomList2;



            //int current = 0;
            //PropertyInfo[] cursors = null;

            //if (cursors == null)
            //    cursors = typeof(System.Windows.Forms.Cursors).GetProperties();
            //int iii = 0;
            //System.Windows.Forms.Cursor c = new System.Windows.Forms.Cursor(())
            //Mouse.OverrideCursor = (System.Windows.Forms.Cursor)cursors[(current++) % cursors.Length].GetValue(null, new object[] { });

            this.list_0 = new List<string>()
            {
                "#7EDD7A",
                "#23E3FD",
                "#F16A6A",
                "#F98F56",
                "#888788"
            };
            this.list_1 = new List<string>()
            {
                "温馨大床",
                "豪华双人",
                "标准大床",
                "商务大床"
            };
            this.list_2 = new List<double>()
            {
                47,
                58,
                100,
                99,
                10
            };
            this.brushConverter_0 = new BrushConverter();
            this.observableCollection_0 = new ObservableCollection<AyArcModel>();
            for (int i = 0; i < 4; i++)
            {
                AyArcModel ayArcModel = new AyArcModel();
                ayArcModel.NameValue = (this.list_2[i]);
                ayArcModel.Color = ((Brush)this.brushConverter_0.ConvertFromString(this.list_0[i]));
                ayArcModel.Name = (this.list_1[i]);
                this.observableCollection_0.Add(ayArcModel);
            }
            this.arc.ArcSource = (this.observableCollection_0);
            this.dispatcherTimer_0 = new DispatcherTimer();
            this.dispatcherTimer_0.Tick += new EventHandler(this.dispatcherTimer_0_Tick);
            this.dispatcherTimer_0.Interval = new TimeSpan(0, 0, 0, 1, 0);
            //this.cboFontWeights.Items.Add(FontWeights.Black);
            //this.cboFontWeights.Items.Add(FontWeights.Bold);
            //this.cboFontWeights.Items.Add(FontWeights.DemiBold);
            //this.cboFontWeights.Items.Add(FontWeights.ExtraBlack);
            //this.cboFontWeights.Items.Add(FontWeights.ExtraBold);
            //this.cboFontWeights.Items.Add(FontWeights.ExtraLight);
            //this.cboFontWeights.Items.Add(FontWeights.Heavy);
            //this.cboFontWeights.Items.Add(FontWeights.Light);
            //this.cboFontWeights.Items.Add(FontWeights.Medium);
            //this.cboFontWeights.Items.Add(FontWeights.Regular);
            //this.cboFontWeights.Items.Add(FontWeights.SemiBold);
            //this.cboFontWeights.Items.Add(FontWeights.Thin);
            //this.cboFontWeights.Items.Add(FontWeights.UltraBlack);
            //this.cboFontWeights.Items.Add(FontWeights.UltraBold);
            //this.cboFontWeights.Items.Add(FontWeights.Normal);
            //this.cboFontWeights.Items.Add(FontWeights.UltraLight);
            //this.cboFontWeights.SelectedItem = FontWeights.Normal;

            var taskbarinfo = new TaskbarItemInfo();

            //0 ~ 1.0 是进度值

            taskbarinfo.ProgressValue = 1.0 / 3 * 2;

            taskbarinfo.ProgressState = TaskbarItemProgressState.Normal;



            //通过Window类型的TaskbarItemInfo属性设置TaskbarItemInfo对象

            this.TaskbarItemInfo = taskbarinfo;




            AyExtension.SetAyWindowMouseLeftButtonMove(this);
            this.dispatcherTimer_0.Start();
        }
        private void dispatcherTimer_0_Tick(object sender, EventArgs e)
        {
            Random random = new Random();
            this.observableCollection_0[0].NameValue = ((double)random.Next(100, 1200));
            this.observableCollection_0[1].NameValue = ((double)random.Next(100, 1200));
            this.observableCollection_0[2].NameValue = ((double)random.Next(100, 1200));
            this.observableCollection_0[3].NameValue = ((double)random.Next(100, 1200));
        }
        private void ButtonChangeHeaderIcon_Click(object sender, RoutedEventArgs e)
        {
            //ChangeHeaderIcon win = UnityContainerManager.ResolveSingleInstance<ChangeHeaderIcon>();
            //win.Owner = this;
            //win.Show();

        }



        private void EmtLayout_Click(object sender, RoutedEventArgs e)
        {

        }

        private void emtViewMode_Checked(object sender, RoutedEventArgs e)
        {
            //listViewRoomStatus.SetResourceReference(FrameworkElement.StyleProperty, "Main.AySimplyListViewImageView");
            //AyListBoxSelector.SetEnabled(listViewRoomStatus, false);
            //AyListBoxSelector.SetEnabled(listViewRoomStatus, true);
        }

        private void emtViewMode_Unchecked(object sender, RoutedEventArgs e)
        {
            //listViewRoomStatus.SetResourceReference(FrameworkElement.StyleProperty, "Main.AySimplyListView");
            //AyListBoxSelector.SetEnabled(listViewRoomStatus, false);
            //AyListBoxSelector.SetEnabled(listViewRoomStatus, true);
        }

        private void Thumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
        {
            UIElement thumb = e.Source as UIElement;
            Canvas.SetTop(thumb, 0);
            var minWidth = regionLeft.MinWidth;
            var maxWidth = regionLeft.MaxWidth;
            if (myCanvas.ActualWidth + 2 + e.HorizontalChange <= minWidth)
            {
                regionLeft.Width = minWidth;
                Canvas.SetRight(thumb, 0);
                return;
            }
            if (myCanvas.ActualWidth + 2 + e.HorizontalChange >= maxWidth)
            {
                regionLeft.Width = maxWidth;
                Canvas.SetRight(thumb, 0);
                return;
            }

            regionLeft.Width = myCanvas.ActualWidth + e.HorizontalChange;
            //    防止Thumb控件被拖出容器。  
            //    if (nTop <= 0)
            //        nTop = 0;
            //    if (nTop >= (g.Height - myThumb.Height))
            //        nTop = g.Height - myThumb.Height;
            //    if (nLeft <= 0)
            //        nLeft = 0;
            //    if (nLeft >= (g.Width - myThumb.Width))
            //        nLeft = g.Width - myThumb.Width;
            //    Canvas.SetTop(myThumb, nTop);
            //    Canvas.SetLeft(myThumb, nLeft);
            //    tt.Text = "Top:" + nTop.ToString() + "\nLeft:" + nLeft.ToString(); 
        }
        private void RadioButtonMember_Click(object sender, RoutedEventArgs e)
        {
            AyWindowManager<Member>.Show(delegate (Member win)
            {
                win.Owner = this;
            }, null);

            //AyWindowManager<MySkinSetWindow>.Show((t) =>
            //{
            //    t.Owner = this;
            //    t.ShowInTaskbar = false;
            //    //t.AfterSetSkinMethodOverride = () =>
            //    //{
            //    //    try
            //    //    {
            //    //        for (var i = ayuiTaskBar.ContextMenu.Items.Count - 1; i >= 0; i--)
            //    //        {
            //    //            MenuItem item = ayuiTaskBar.ContextMenu.Items[i] as MenuItem;
            //    //            if (item == null) continue;
            //    //            var key = item.GetDynamicResourceKey(HeaderedItemsControl.HeaderProperty) as string;
            //    //            if (!string.IsNullOrEmpty(key))
            //    //                item.SetResourceReference(HeaderedItemsControl.HeaderProperty, key);
            //    //        }
            //    //    }
            //    //    catch (System.Exception ex)
            //    //    {
            //    //        //MyAyMessageBox.Show(ex.Message);

            //    //    }
            //    //};

            //}, null);
        }

        private void AyWindow_Activated(object sender, EventArgs e)
        {
            if (this.IsActive)
            {
                //if (notificationTimer.Enabled)
                //{
                //    notificationTimer.Enabled = false; // 停止闪烁通知区域图标
                //    notifyIcon.Icon = icons[0];
                //}
                Common.WindowExtensions.FlashWindow(this, 1000, 1500);
            }
            else
            {

                Common.WindowExtensions.StopFlashingWindow(this); // 停止闪烁任务栏
            }
        }

        private void RadioButton_Click(object sender, RoutedEventArgs e)
        {
            var reportHotel = new Hotel.Win.Views.ReportWin();
            reportHotel.Show();
            //var reportForm = new ReportForm();
            //WindowInteropHelper helper = new WindowInteropHelper(this);
            ////reportForm.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            //reportForm.ShowReport(helper.Handle);
            ////AyWindowManager<Report>.Show(delegate (Report win)
            ////{
            ////    win.Owner = this;
            ////}, null);
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            if (CloseIsHideWindow && System.Windows.Application.Current.MainWindow != null)
            {
                System.Windows.Application.Current.MainWindow.Hide();
                e.Cancel = true;    //不关闭窗口
            }
            else
            {
                ayuiTaskBar.Dispose();
                base.OnClosing(e);
            }
        }
        private void MenuItemSite_Click(object sender, RoutedEventArgs e)
        {
            Process.Start("http://www.utriphotel.com");
        }
        private void MenuItemClose_Click(object sender, RoutedEventArgs e)
        {
            CloseIsHideWindow = false;
            this.Close();
        }
        private void AyuiTaskBar_OnPreviewTrayContextMenuOpen(object sender, RoutedEventArgs e)
        {
            try
            {
                //var dd = ayuiTaskBar.Resources;
                //TextBlockTest.SetResourceReference(TextBlock.TextProperty, "ShowInterface");
                //MenuItemTest.SetResourceReference(HeaderedItemsControl.HeaderProperty, "HiddenInterface");
                ////(FindResource("mainwindowTrayIconMenu") as ContextMenu).Refresh();

                //for (var i = ayuiTaskBar.ContextMenu.Items.Count - 1; i >= 0; i--)
                //{
                //    MenuItem item = ayuiTaskBar.ContextMenu.Items[i] as MenuItem;
                //    if (item == null) continue;
                //    var key = item.GetDynamicResourceKey(HeaderedItemsControl.HeaderProperty) as string;
                //    if (!string.IsNullOrEmpty(key))
                //        item.SetResourceReference(HeaderedItemsControl.HeaderProperty, key);
                //}

            }
            catch (System.Exception ex)
            {
                int iii = 0;
            }
        }

        public void ShowActiveWindow(object x)
        {
            if (System.Windows.Application.Current.MainWindow != null)
            {
                if (System.Windows.Application.Current.MainWindow.IsVisible
                    && WindowState != WindowState.Minimized
                    && System.Windows.Application.Current.MainWindow.IsActive)
                {
                    System.Windows.Application.Current.MainWindow.Hide();
                    return;
                }

                if (!System.Windows.Application.Current.MainWindow.IsVisible)
                {
                    WindowState = WindowState.Normal;
                    System.Windows.Application.Current.MainWindow.Show();
                    System.Windows.Application.Current.MainWindow.Activate();
                }
                else if (!System.Windows.Application.Current.MainWindow.IsActive)
                {
                    WindowState = WindowState.Normal;
                    System.Windows.Application.Current.MainWindow.Show();
                    System.Windows.Application.Current.MainWindow.Activate();
                }
                else
                {
                    System.Windows.Application.Current.MainWindow.Show();
                }
            }

            //System.Windows.Application.Current.MainWindow = new MainWindow();
            //System.Windows.Application.Current.MainWindow.Show();
        }
        public void HideWindow(object x)
        {
            if (CloseIsHideWindow && System.Windows.Application.Current.MainWindow != null)
            {
                System.Windows.Application.Current.MainWindow.Hide();
            }
        }

        public void ShowWindow(object x)
        {
            if (CloseIsHideWindow)
            {
                if (System.Windows.Application.Current.MainWindow != null)
                {
                    WindowState = WindowState.Normal;
                    System.Windows.Application.Current.MainWindow.Show();
                    System.Windows.Application.Current.MainWindow.Activate();
                    return;
                }
                //System.Windows.Application.Current.MainWindow = new MainWindow();
                //System.Windows.Application.Current.MainWindow.Show();
            }
        }

        private void MenuItemAbout_Click(object sender, RoutedEventArgs e)
        {

        }
    }


























    public partial class Main : AyWindow
    {
        #region 控制器
        private Actions<MainController> _mvc;
        public Actions<MainController> Mvc
        {
            get
            {
                if (_mvc == null)
                {
                    _mvc = new Actions<MainController>(DataContext as MainController);
                }
                return _mvc;
            }
        }
        #endregion
    }
}
